get_town_adm_hs<-function(data,year){
  data_full<-data
  
  data<- as.data.frame(data_full %>% group_by(judet,liceu_repartizat,liceu_repartizat_orig,an_adm,town_hs_adm) %>% ungroup())
  
  #Get town directly, when preceded by "city", "town", "village", etc
  data[grepl(".+,", data$liceu_repartizat),]$town_hs_adm<-sub(".+,", "", data$liceu_repartizat)[grepl(".+,", data$liceu_repartizat)]
  replace_string<-paste0(".+( ORASUL )|.+( COM )|.+( ORAS )|.+( MUNICIPIUL )|.+( LOC )|.+( LOCALITATEA )|",
                         ".+( \\(ENERGETIC\\) )|.+( \\(AUTO\\) )|.+( \\(EC\\. TEODOROIU\\) )|.+( ECONOMIC\\, ADMINISTRATIV SI DE SERVICII )|",
                         ".+( LOC. )|.+( MUN. )|.+( SAT )|.+( COMUNA )|.+( ORAȘ )|.+( MUN )|.+( COM\\. )|.+\" |.+\\d |.+\", |.+\"")
  data[grepl(replace_string, data$liceu_repartizat),]$town_hs_adm<-sub(replace_string, "", data[grepl(replace_string, data$liceu_repartizat),]$liceu_repartizat)
  #Get town for remaining obervations
  replace_string<-paste0(".+( TEHNOLOGIC DE TURISM SI ALIMENTATIE )|.+( MARMATIA )|.+( AL BANATULUI MONTAN )|",
                         ".+( PARTICULAR )|.+( DE ARTA )|.+( DEFICIENTI DE VEDERE )|.+( BILINGV ROMINO-CROAT )|",
                         ".+( DE CONSTRUCTII SI PROTECTIA MEDIULUI )|.+( PROFESIONALA DE COOPERATIE )|",
                         ".+( DE PROTECTIA MEDIULUI  )|.+( WALDORF )|(FEG )|.+( DE VEST )|",
                         ".+( PENTRU EDUCATIE INCLUZIVA )|.+( DE ARTE SI MESERII )|",
                         ".+( CONSTR. CAI FERATE )|.+( DE CHIMIE INDUSTRIALA )|",
                         ".+( CONSTRUCTII MONTAJ )|.+( INDUSTRIAL MINIER )|.+( MINIER )|",
                         ".+( DE COOPERATIE )|.+( INDUSTRIE USOARA )|.+( ECONOMIC-ADMINISTRATIV)|",
                         ".+( MESERII SI SERVICII )|.+( INDUSTRIE MICA SI SERVICII )|.+( NATIONALA DE GAZ )|",
                         ".+( DE MUZICA SI ARTE PLASTICE )|.+( CU PROGRAM DE ATLETISM )|.+( DE MUZICA )|",
                         ".+( ADMINISTRATIV SI DE SERVICII )|.+( ALIMENTATIE PUBLICA )|.+( CU PROGRAM SPORTIV )|",
                         ".+( FORESTIER )|.+( INDUSTRIA STICLEI )|.+( COOPERATIST )|.+( COOPERATIE )|",
                         ".+( DE MARINA )|.+( DE AGRICULTURA SI ECONOMIE )|.+( CONSTRUCTII CAI FERATE )|",
                         ".+( DE TRANSPORTURI AUTO )|.+( BILINGV ROMANO-CROAT )|.+( TEHNIC DE TRANSPORTURI )|",
                         ".+( SPECIAL PENTRU DEFICIENTI DE AUZ )|.+( ADVENTIST )|",
                         ".+( TRANSPORTURI CAI FERATE )|.+( VOCATIONAL DE ARTA )|.+( ROMANO-CATOLIC )|.+( SPECIAL )|.+( AUTO )|",
                         ".+( SILVIC )|.+( TEHNIC )|.+( CONSTRUCTII DE MASINI )|.+( METALURGIC )|.+( PETROL )|",
                         ".+( BANATEAN )|.+( CARASAN )|.+( ALIMENTARA )|.+( PENTICOSTAL )|.+( BAPTIST )|.+( AGRICOL )|.+( DE AFACERI )|",
                         ".+( REFORMAT )|.+( TEOLOGIC )|.+( ORTODOX )|.+( TEHNOLOGIC FORESTIER )|.+( TEHNOLOGIC CONSTRUCTII DE MASINI )|",
                         ".+( SPORTIV )|.+( SANITAR )|.+( ENERGETIC )|.+( TEHNOLOGIC )|.+( PEDAGOGIC )|.+( TEORETIC )|",
                         ".+( DE INFORMATICA )|.+( ECONOMIC )|.+( TRANSPORTURI )|.+( ADMINISTRATIV )|.+( DE TURISM )|.+( PENTRU TRANSPORT RUTIER )|",
                         ".+( MAGHIARA )|.+( TELECOMUNICATII )|.+( DE ARTE )|.+( CONSTRUCTII )|.+( SERVICII )|.+( AUTOMECANICA )|.+( NATIONAL )|",
                         ".+( FEROVIAR )|.+( TEXTIL )|(GR. SC. )|(CENTRUL SCOLAR )|(GRUP SCOLAR INDUSTRIAL )|",
                         ".+(THE CAMBRIDGE INTERNATIONAL SCHOOL IN )|.+( DIN )|(GRI )|(GRUP SCOLAR )|(GRUPUL SCOLAR INDUSTRIAL )|(GRUPUL SCOLAR )|(LICEUL )") 
  data[grepl(replace_string, data$liceu_repartizat) & is.na(data$town_hs_adm),]$town_hs_adm<-
    sub(replace_string, "", data[grepl(replace_string,data$liceu_repartizat) & is.na(data$town_hs_adm),]$liceu_repartizat)
  
  
  
  
  
  
  

    data$town_hs_adm<-if_else(data$judet=='GIURGIU' & grepl("MIRON NICOLESCU",data$liceu_repartizat),"GIURGIU",data$town_hs_adm)

 
  data$town_hs_adm<-if_else(data$judet=='BUZAU' & grepl("ALEXANDRU MARGHILOMAN",data$liceu_repartizat),"BUZAU",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='BACAU' & grepl("BC",data$liceu_repartizat),"BACAU",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='BIHOR' & grepl(" STEI",data$liceu_repartizat),"STEI",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='COVASNA' & grepl("INT\\. BUZAULUI",data$liceu_repartizat),"INTORSURA BUZAULUI",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='DOLJ' & grepl("MOFLENI",data$liceu_repartizat),"CRAIOVA",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='CLUJ' & grepl("GHERLA",data$liceu_repartizat),"GHERLA",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='CONSTANTA' & grepl("M. KOGALNICEANU",data$town_hs_adm),"MIHAIL KOGALNICEANU",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='CONSTANTA' & grepl("CALLATIS",data$town_hs_adm),"MANGALIA",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='GALATI' & grepl("PAUL DIMO",data$liceu_repartizat),"GALATI",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='IASI' & grepl("NICOLINA",data$liceu_repartizat),"IASI",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='IASI' & grepl("DEFICIENTI DE VEDERE",data$liceu_repartizat),"TARGU FRUMOS",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='MEHEDINTI' & grepl("DE MARINA",data$town_hs_adm),"ORSOVA",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='MEHEDINTI' & grepl("AUTO",data$town_hs_adm),"DROBETA-TURNU SEVERIN",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='SIBIU' & grepl("AVRIG",data$liceu_repartizat),"AVRIG",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='SIBIU' & grepl("BETANIA",data$liceu_repartizat),"SIBIU",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='VALCEA' & grepl("RM",data$liceu_repartizat),"RAMNICU VALCEA",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='VALCEA' & grepl("BABENI",data$liceu_repartizat),"BABENI",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='VALCEA' & grepl("BAILE OLANESTI",data$liceu_repartizat),"BAILE OLANESTI",data$town_hs_adm)
  


    data$town_hs_adm<-if_else(data$judet=='MEHEDINTI' & grepl("AUTO",data$town_hs_adm),"DROBETA-TURNU SEVERIN",data$town_hs_adm)
    data$town_hs_adm<-if_else(data$judet=='MEHEDINTI' & grepl("DE MARINA",data$town_hs_adm),"ORSOVA",data$town_hs_adm)
    data$town_hs_adm<-if_else(data$judet=='DOLJ' & (grepl("ION MINCU",data$town_hs_adm)),"CRAIOVA",data$town_hs_adm)

  

    data$town_hs_adm<-if_else(data$judet=='IALOMITA' & grepl("SCINTEIA",data$town_hs_adm),"SCANTEIA",data$town_hs_adm)
    data$town_hs_adm<-gsub('SANGERU','SINGERU',data$town_hs_adm)
    data$town_hs_adm<-if_else(data$judet=='MARAMURES' & grepl("SPORTIV",data$town_hs_adm),"BAIA MARE",data$town_hs_adm)
    

  

    data$town_hs_adm<-if_else(data$judet=='HUNEDOARA' & grepl("LUPENI",data$town_hs_adm),"LUPENI",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('TRAIAN',data$liceu_repartizat) & grepl('MEHEDINTI',data$judet),"DROBETA-TURNU SEVERIN",data$town_hs_adm)
    
    
  
  
  

    data$town_hs_adm<-if_else(data$judet=='IASI' & grepl("WALDORF",data$town_hs_adm),"IASI",data$town_hs_adm)
    data$town_hs_adm<-if_else(data$judet=='IASI' & grepl("COLEGIUL NATIONAL,",data$town_hs_adm),"IASI",data$town_hs_adm)
    data$town_hs_adm<-if_else(data$judet=='NEAMT' & grepl("VINATORI",data$liceu_repartizat),"VANATORI NEAMT",data$town_hs_adm)
    
    data$town_hs_adm<-if_else(data$judet=='MEHEDINTI' & grepl("TRAIAN",data$liceu_repartizat),"DROBETA-TURNU SEVERIN",data$town_hs_adm)
    
    data$town_hs_adm<-if_else(data$judet=='MEHEDINTI' & grepl("COLEGIUL TEHNIC DE TRANSPORTURI AUTO",data$liceu_repartizat),"DROBETA-TURNU SEVERIN",data$town_hs_adm)
    

  

    data$town_hs_adm<-if_else(grepl('CURTEA DE ARGES',data$town_hs_adm),"CURTEA DE ARGES",data$town_hs_adm)
    
    data$town_hs_adm<-if_else(grepl('SEBES',data$town_hs_adm) & grepl('ALBA',data$judet),"SEBES",data$town_hs_adm)
    
    data$town_hs_adm<-if_else(grepl('GEORGE VALSAN',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('ANA ASLAN',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('ION GHICA',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('GHEORGHE MUNTEANU MURGOCI',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('NICOLAE BALCESCU',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('COSTIN D\\. NENITESCU',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('EDMOND NICOLAU',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('PANAIT ISTRATI',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('HARICLEA DARCLEE',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('D\\. P\\. PERPESSICIUS',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('SPORTIV',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('MIHAIL SEBASTIAN',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('NICOLAE IORGA',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('PANAIT CERNA',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('ANGHEL SALIGNY',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('GHEORGHE K\\. CONSTANTINESCU',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('GRIGORE MOISIL',data$liceu_repartizat) & data$judet=='BRAILA',"BRAILA",data$town_hs_adm)
    
    data$town_hs_adm<-if_else(grepl('NICOLAE ONCESCU',data$liceu_repartizat) & data$judet=='BRAILA',"IANCA",data$town_hs_adm)
    data$town_hs_adm<-if_else(grepl('CONSTANTIN ANGELESCU',data$liceu_repartizat) & data$judet=='BRAILA',"IANCA",data$town_hs_adm)
    
    data$town_hs_adm<-if_else(grepl('GEORGE VILSAN',data$liceu_repartizat) & data$judet=='BRAILA',"FAUREI",data$town_hs_adm)
    
    data$town_hs_adm<-if_else(grepl('SCOALA PROFESIONALA SIG',data$liceu_repartizat) & data$judet=='SALAJ',"SAG",data$town_hs_adm)
    
    data$town_hs_adm<-if_else(data$liceu_repartizat=="LICEUL TEHNOLOGIC" & data$judet=='MEHEDINTI',"DROBETA-TURNU SEVERIN",data$town_hs_adm)
    

  
  
  
  
  #ADJUSTMENTS BY COUNTY
  names<-unique(data$judet)
  data<-data %>% 
    group_split(judet)
  names(data)<-names
  
  
  
  
  
  
  data[['ALBA']]$town_hs_adm<-if_else(grepl("SEBES",data[['ALBA']]$liceu_repartizat),"SEBES",data[['ALBA']]$town_hs_adm)
  
  data[['ARAD']]$town_hs_adm<-if_else(grepl("ADAM MULLER GUTTENBRUNN",data[['ARAD']]$liceu_repartizat),"ARAD",data[['ARAD']]$town_hs_adm)
  data[['ARAD']]$town_hs_adm<-if_else(grepl("CONCORD",data[['ARAD']]$liceu_repartizat),"ARAD",data[['ARAD']]$town_hs_adm)
  
  data[['ARGES']]$town_hs_adm<-if_else(grepl("ALEXANDRU IONESCU",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm) #2016
  data[['ARGES']]$town_hs_adm<-if_else(data[['ARGES']]$liceu_repartizat=="LICEUL TEHNOLOGIC","VEDEA",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("PETRESCU",data[['ARGES']]$liceu_repartizat),"STALPENI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("CURTEA",data[['ARGES']]$liceu_repartizat),"CURTEA DE ARGES",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("PETRE IONESCU MUSCEL",data[['ARGES']]$liceu_repartizat),"DOMNESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("DINU BRATIANU",data[['ARGES']]$liceu_repartizat),"STEFANESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("TEIULEANU",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("BRANCUSI",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("DOBRESCU",data[['ARGES']]$liceu_repartizat),"CURTEA DE ARGES",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("ELIM",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("DACIA",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("ASTRA",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("DINU LIPATTI",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("VIITORUL",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else((grepl("IUSTIN PATRIARHUL",data[['ARGES']]$liceu_repartizat)),"CAMPULUNG",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else((grepl("NEAGOE VODA BASARAB",data[['ARGES']]$liceu_repartizat)),"CURTEA DE ARGES",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("MIHALACHE",data[['ARGES']]$liceu_repartizat),"TOPOLOVENI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("CANTACUZINO",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("BARBU",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("CAROL",data[['ARGES']]$liceu_repartizat),"CAMPULUNG",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("BARBILIAN",data[['ARGES']]$liceu_repartizat),"CAMPULUNG",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("NENITESCU",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("ARMAND",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("VLAICU VODA",data[['ARGES']]$liceu_repartizat),"CURTEA DE ARGES",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("ION C. BRATIANU",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("REBREANU",data[['ARGES']]$liceu_repartizat),"MOZACENI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("SLAVESCU",data[['ARGES']]$liceu_repartizat),"RUCAR",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("VITEAZUL",data[['ARGES']]$liceu_repartizat),"PITESTI",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("VLAICU VODA",data[['ARGES']]$liceu_repartizat),"CURTEA DE ARGES",data[['ARGES']]$town_hs_adm)
  data[['ARGES']]$town_hs_adm<-if_else(grepl("COLIBASI",data[['ARGES']]$liceu_repartizat),"MIOVENI",data[['ARGES']]$town_hs_adm)
  
  
  data[['BACAU']]$town_hs_adm<-if_else(grepl("ASACHI",data[['BACAU']]$liceu_repartizat),"ONESTI",data[['BACAU']]$town_hs_adm)
  data[['BACAU']]$town_hs_adm<-if_else(grepl("STEFAN CEL MARE",data[['BACAU']]$liceu_repartizat),"BACAU",data[['BACAU']]$town_hs_adm)
  
  data[['BOTOSANI']]$town_hs_adm<-if_else((grepl("GRUPUL SCOLAR DE COOPERATIE",data[['BOTOSANI']]$liceu_repartizat)),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else((grepl("CENTRUL DE STUDII STEFAN CEL MARE SI SFANT",data[['BOTOSANI']]$liceu_repartizat)),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("SPORTIV",data[['BOTOSANI']]$liceu_repartizat),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("INDUSTRIE USOARA$",data[['BOTOSANI']]$liceu_repartizat),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("ORTODOX",data[['BOTOSANI']]$liceu_repartizat) & grepl("SFANTUL GHEORGHE",data[['BOTOSANI']]$liceu_repartizat),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("STEFAN LUCHIAN",data[['BOTOSANI']]$liceu_repartizat),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("ORTODOX",data[['BOTOSANI']]$liceu_repartizat)& (grepl("IOAN IACOB",data[['BOTOSANI']]$liceu_repartizat)),"DOROHOI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("PETRU RARES",data[['BOTOSANI']]$liceu_repartizat),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("NEGREANU",data[['BOTOSANI']]$liceu_repartizat),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("CIUCA",data[['BOTOSANI']]$liceu_repartizat),"SAVENI",data[['BOTOSANI']]$town_hs_adm)
  data[['BOTOSANI']]$town_hs_adm<-if_else(grepl("IORGA",data[['BOTOSANI']]$liceu_repartizat),"BOTOSANI",data[['BOTOSANI']]$town_hs_adm)
  
  data[['BIHOR']]$town_hs_adm<-if_else(grepl("BOCOCI",data[['BIHOR']]$liceu_repartizat),"ORADEA",data[['BIHOR']]$town_hs_adm)
  data[['BIHOR']]$town_hs_adm<-if_else(grepl("SACUIENI",data[['BIHOR']]$liceu_repartizat),"SACUENI",data[['BIHOR']]$town_hs_adm)
  data[['BIHOR']]$town_hs_adm<-if_else(grepl("STEI",data[['BIHOR']]$liceu_repartizat),"STEI",data[['BIHOR']]$town_hs_adm)
  data[['BIHOR']]$town_hs_adm<-if_else(grepl("CIORDAS",data[['BIHOR']]$liceu_repartizat),"BEIUS",data[['BIHOR']]$town_hs_adm)
  
  data[['BISTRITA-NASAUD']]$town_hs_adm<-if_else(grepl("SANITAR",data[['BISTRITA-NASAUD']]$liceu_repartizat),"BISTRITA",data[['BISTRITA-NASAUD']]$town_hs_adm)
  data[['BISTRITA-NASAUD']]$town_hs_adm<-if_else(grepl("BISTRTA",data[['BISTRITA-NASAUD']]$liceu_repartizat),"BISTRITA",data[['BISTRITA-NASAUD']]$town_hs_adm)
  
  data[['BRAILA']]$town_hs_adm<-if_else(grepl("MATEI BASARAB",data[['BRAILA']]$liceu_repartizat),"MAXINENI",data[['BRAILA']]$town_hs_adm)
  
  data[['BRASOV']]$town_hs_adm<-if_else((grepl("DOAMNA STANCA",data[['BRASOV']]$liceu_repartizat)),"FAGARAS",data[['BRASOV']]$town_hs_adm)
  data[['BRASOV']]$town_hs_adm<-if_else((grepl("FELDIOARA",data[['BRASOV']]$liceu_repartizat)),"FELDIOARA",data[['BRASOV']]$town_hs_adm)
  
  data[['BUZAU']]$town_hs_adm<-if_else(grepl("RADU VLADESCU",data[['BUZAU']]$liceu_repartizat),"PATARLAGELE",data[['BUZAU']]$town_hs_adm)
  data[['BUZAU']]$town_hs_adm<-if_else(grepl("DEFICIENTI DE VEDERE",data[['BUZAU']]$liceu_repartizat),"BUZAU",data[['BUZAU']]$town_hs_adm)
  data[['BUZAU']]$town_hs_adm<-if_else(grepl("IOLANDA",data[['BUZAU']]$liceu_repartizat),"BUZAU",data[['BUZAU']]$town_hs_adm)
  
  data[['CLUJ']]$town_hs_adm<-if_else((grepl("OCTAVIAN STROIA",data[['CLUJ']]$liceu_repartizat)),"CLUJ-NAPOCA",data[['CLUJ']]$town_hs_adm)
  data[['CLUJ']]$town_hs_adm<-if_else(grepl("CLUJ-NAPOCA",data[['CLUJ']]$liceu_repartizat),"CLUJ-NAPOCA",data[['CLUJ']]$town_hs_adm)
  
  data[['CONSTANTA']]$town_hs_adm<-if_else(grepl("GEORGE CALINESCU",data[['CONSTANTA']]$liceu_repartizat),"CONSTANTA",data[['CONSTANTA']]$town_hs_adm)
  data[['CONSTANTA']]$town_hs_adm<-if_else(grepl("EFORIE",data[['CONSTANTA']]$liceu_repartizat),"EFORIE",data[['CONSTANTA']]$town_hs_adm)
  data[['CONSTANTA']]$town_hs_adm<-if_else(grepl("HURMUZESCU",data[['CONSTANTA']]$liceu_repartizat),"MEDGIDIA",data[['CONSTANTA']]$town_hs_adm)
  
  data[['COVASNA']]$town_hs_adm<-if_else((grepl("BERDE ARON",data[['COVASNA']]$liceu_repartizat)),"SFANTU GHEORGHE",data[['COVASNA']]$town_hs_adm)
  
  data[['DOLJ']]$town_hs_adm<-if_else((grepl("ANGHEL SALIGNY",data[['DOLJ']]$liceu_repartizat)),"CRAIOVA",data[['DOLJ']]$town_hs_adm)
  data[['DOLJ']]$town_hs_adm<-if_else((grepl("ION MINCU",data[['DOLJ']]$liceu_repartizat)),"CRAIOVA",data[['DOLJ']]$town_hs_adm)
  
  data[['GALATI']]$town_hs_adm<-if_else((grepl("DIMITRIE CANTEMIR",data[['GALATI']]$liceu_repartizat)),"GALATI",data[['GALATI']]$town_hs_adm)
  
  data[['GORJ']]$town_hs_adm<-if_else((grepl("BILTA",data[['GORJ']]$town_hs_adm)|grepl("RUNCU",data[['GORJ']]$town_hs_adm)),"BILTA, RUNCU",data[['GORJ']]$town_hs_adm)
  data[['GORJ']]$town_hs_adm<-if_else((grepl("ION MINCU",data[['GORJ']]$liceu_repartizat)),"TARGU-JIU",data[['GORJ']]$town_hs_adm)
  
  data[['GIURGIU']]$town_hs_adm<-if_else(grepl("TEOCTIST",data[['GIURGIU']]$liceu_repartizat),"GIURGIU",data[['GIURGIU']]$town_hs_adm)
  data[['GIURGIU']]$town_hs_adm<-if_else(grepl("MIRON NICOLESCU",data[['GIURGIU']]$liceu_repartizat),"GIURGIU",data[['GIURGIU']]$town_hs_adm)
  data[['GIURGIU']]$town_hs_adm<-if_else(grepl("IOAN BALANESCU",data[['GIURGIU']]$liceu_repartizat),"GIURGIU",data[['GIURGIU']]$town_hs_adm)
  data[['GIURGIU']]$town_hs_adm<-if_else(grepl("ION BARBU",data[['GIURGIU']]$liceu_repartizat),"GIURGIU",data[['GIURGIU']]$town_hs_adm)
  
  
  data[['HUNEDOARA']]$town_hs_adm<-if_else(grepl("HUNEDOARA",data[['HUNEDOARA']]$liceu_repartizat),"HUNEDOARA",data[['HUNEDOARA']]$town_hs_adm)
  data[['HUNEDOARA']]$town_hs_adm<-if_else(grepl("LUPENI",data[['HUNEDOARA']]$liceu_repartizat),"LUPENI",data[['HUNEDOARA']]$town_hs_adm)
  
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("MARK TWAIN",data[['ILFOV']]$liceu_repartizat),"VOLUNTARI",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("HULUBEI",data[['ILFOV']]$liceu_repartizat),"MAGURELE",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("DOAMNA CHIAJNA",data[['ILFOV']]$liceu_repartizat),"ROSU",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("DUMITRU DUMITRESCU",data[['ILFOV']]$liceu_repartizat),"MAGURELE",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("VINTILA BRATIANU",data[['ILFOV']]$liceu_repartizat),"DRAGOMIRESTI-VALE",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("ROSETTI",data[['ILFOV']]$liceu_repartizat),"VIDRA",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("LALESCU",data[['ILFOV']]$liceu_repartizat),"BRANESTI",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("IOAN PETRUS",data[['ILFOV']]$liceu_repartizat),"OTOPENI",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("PAMFIL SEICARU",data[['ILFOV']]$liceu_repartizat),"CIOROGARLA",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("MIHAIL KOGALNICEANU",data[['ILFOV']]$liceu_repartizat),"SNAGOV",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("STIRBEY",data[['ILFOV']]$liceu_repartizat),"BUFTEA",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("NICOLAE BALCESCU",data[['ILFOV']]$liceu_repartizat),"VOLUNTARI",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("CEZAR NICOLAU",data[['ILFOV']]$liceu_repartizat),"BRANESTI",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("FILOFTEIA",data[['ILFOV']]$liceu_repartizat),"BRANESTI",data[['ILFOV']]$town_hs_adm)
  data[['ILFOV']]$town_hs_adm<-if_else(grepl("PIETRARU",data[['ILFOV']]$liceu_repartizat),"BRANESTI",data[['ILFOV']]$town_hs_adm)
  
  data[['IASI']]$town_hs_adm<-if_else((grepl("SCHEIA",data[['IASI']]$town_hs_adm)),"SCHEIA",data[['IASI']]$town_hs_adm)
  data[['IASI']]$town_hs_adm<-if_else((grepl("PASCANI",data[['IASI']]$town_hs_adm)),"PASCANI",data[['IASI']]$town_hs_adm)
  data[['IASI']]$town_hs_adm<-if_else((grepl("TARGU FRUMOS",data[['IASI']]$town_hs_adm)),"TARGU FRUMOS",data[['IASI']]$town_hs_adm)
  data[['IASI']]$town_hs_adm<-if_else((grepl("NICOLINA",data[['IASI']]$town_hs_adm)),"IASI",data[['IASI']]$town_hs_adm)
  
  data[['IALOMITA']]$town_hs_adm<-if_else((grepl("FIERBINTI",data[['IALOMITA']]$town_hs_adm)),"FIERBINTI",data[['IALOMITA']]$town_hs_adm)
  data[['IALOMITA']]$town_hs_adm<-if_else(grepl("ORTODOX",data[['IALOMITA']]$liceu_repartizat) & grepl("IOAN GURA DE AUR",data[['IALOMITA']]$liceu_repartizat),"SLOBOZIA",data[['IALOMITA']]$town_hs_adm)
  
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("TRANSPORTURI AUTO",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("GHEORGHE TITEICA",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("COLEGIUL NATIONAL \"TRAIAN\"",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("THEODOR COSTESCU",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("STEFAN ODOBLEJA",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("DECEBAL",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("TUDOR",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("SERBAN CIOCULESCU",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("DIERNA",data[['MEHEDINTI']]$liceu_repartizat),"ORSOVA",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("PAULIAN",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("IONESCU",data[['MEHEDINTI']]$liceu_repartizat),"SISESTI",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("VLADIMIRESCU",data[['MEHEDINTI']]$liceu_repartizat),"TUDOR VLADIMIRESCU",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("PAULIAN",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("CONSTANTIN",data[['MEHEDINTI']]$liceu_repartizat),"BAIA DE ARAMA",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("BASARAB",data[['MEHEDINTI']]$liceu_repartizat),"STREHAIA",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("GOMOIU",data[['MEHEDINTI']]$liceu_repartizat),"VANJU MARE",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("LALESCU",data[['MEHEDINTI']]$liceu_repartizat),"ORSOVA",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("SALAGEAN",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("INDUSTRIAL DE MARINA",data[['MEHEDINTI']]$liceu_repartizat),"ORSOVA",data[['MEHEDINTI']]$town_hs_adm)
  data[['MEHEDINTI']]$town_hs_adm<-if_else(grepl("AUTO",data[['MEHEDINTI']]$liceu_repartizat),"DROBETA-TURNU SEVERIN",data[['MEHEDINTI']]$town_hs_adm)
  
  
  data[['MURES']]$town_hs_adm<-if_else(grepl("ROMANO-AMERICANA",data[['MURES']]$liceu_repartizat),"TARGU-MURES",data[['MURES']]$town_hs_adm)#2014
  data[['MURES']]$town_hs_adm<-if_else(grepl("JEBELEAN",data[['MURES']]$liceu_repartizat),"SANNICOLAU-MARE",data[['MURES']]$town_hs_adm)#2014
  data[['MURES']]$town_hs_adm<-if_else(grepl("TARGU-MURES",data[['MURES']]$liceu_repartizat),"TARGU MURES",data[['MURES']]$town_hs_adm)#2014
  
  
  data[['NEAMT']]$town_hs_adm<-if_else(grepl("VASILE CONTA",data[['NEAMT']]$liceu_repartizat),"TARGU NEAMT",data[['NEAMT']]$town_hs_adm)
  data[['NEAMT']]$town_hs_adm<-if_else(grepl("MANASTIREA NEAMT",data[['NEAMT']]$liceu_repartizat),"VANATORI NEAMT",data[['NEAMT']]$town_hs_adm)
  data[['NEAMT']]$town_hs_adm<-if_else(grepl("BOLINTIN",data[['NEAMT']]$liceu_repartizat),"BOLINTIN-VALE",data[['NEAMT']]$town_hs_adm)
  data[['NEAMT']]$town_hs_adm<-if_else(grepl("ION CREANGA",data[['NEAMT']]$liceu_repartizat) & grepl('COLEGIUL TEHNIC',data[['NEAMT']]$liceu_repartizat),"TARGU NEAMT",data[['NEAMT']]$town_hs_adm)
  
  data[['PRAHOVA']]$town_hs_adm<-if_else(grepl("BOLDESTI",data[['PRAHOVA']]$liceu_repartizat),"BOLDESTI-SCAENI",data[['PRAHOVA']]$town_hs_adm)
  data[['PRAHOVA']]$town_hs_adm<-if_else(grepl("MANECIU",data[['PRAHOVA']]$liceu_repartizat),"MANECIU",data[['PRAHOVA']]$town_hs_adm)
  data[['PRAHOVA']]$town_hs_adm<-if_else(grepl("CIORANI",data[['PRAHOVA']]$liceu_repartizat),"CIORANI",data[['PRAHOVA']]$town_hs_adm)
  
  
  data[['SALAJ']]$town_hs_adm<-if_else(grepl("CSEREY-GOGA",data[['SALAJ']]$liceu_repartizat),"CRASNA",data[['SALAJ']]$town_hs_adm)
  data[['SALAJ']]$town_hs_adm<-if_else(grepl("SIG",data[['SALAJ']]$town_hs_adm),"SAG",data[['SALAJ']]$town_hs_adm)
  
  data[['SATU-MARE']]$town_hs_adm<-if_else((grepl("SATU MARE",data[['SATU-MARE']]$liceu_repartizat)),"SATU MARE",data[['SATU-MARE']]$town_hs_adm)
  
  data[['SIBIU']]$town_hs_adm<-if_else((grepl("CIBINIUM",data[['SIBIU']]$liceu_repartizat)),"SIBIU",data[['SIBIU']]$town_hs_adm)
  data[['SIBIU']]$town_hs_adm<-if_else((grepl("COPSA MICA",data[['SIBIU']]$liceu_repartizat)),"COPSCA MICA",data[['SIBIU']]$town_hs_adm)
  data[['SIBIU']]$town_hs_adm<-if_else((grepl("AVRIG",data[['SIBIU']]$liceu_repartizat)),"AVRIG",data[['SIBIU']]$town_hs_adm)
  
  data[['SUCEAVA']]$town_hs_adm<-if_else((grepl("CENTRUL DE STUDII STEFAN CEL MARE SI SFANT",data[['SUCEAVA']]$town_hs_adm)),"SUCEAVA",data[['SUCEAVA']]$town_hs_adm)
  data[['SUCEAVA']]$town_hs_adm<-if_else(grepl("MOLDOVENESC",data[['SUCEAVA']]$liceu_repartizat),"CAMPULUNG MOLDOVENESC",data[['SUCEAVA']]$town_hs_adm)
  data[['SUCEAVA']]$town_hs_adm<-if_else(grepl("PIRTESTII",data[['SUCEAVA']]$liceu_repartizat),"PARTESTII DE JOS",data[['SUCEAVA']]$town_hs_adm)
  
  data[['TELEORMAN']]$town_hs_adm<-if_else(grepl("ALEXANRIA",data[['TELEORMAN']]$liceu_repartizat),"ALEXANDRIA",data[['TELEORMAN']]$town_hs_adm)
  data[['TELEORMAN']]$town_hs_adm<-if_else(grepl("DRAGANESTI",data[['TELEORMAN']]$liceu_repartizat),"DRAGANESTI-VLASCA",data[['TELEORMAN']]$town_hs_adm)
  data[['TELEORMAN']]$town_hs_adm<-if_else(grepl("ROSIORI",data[['TELEORMAN']]$liceu_repartizat),"ROSIORII DE VEDE",data[['TELEORMAN']]$town_hs_adm)
  
  data[['VASLUI']]$town_hs_adm<-if_else(grepl("BIRLAD",data[['VASLUI']]$liceu_repartizat),"BARLAD",data[['VASLUI']]$town_hs_adm)
  
  data[['TIMIS']]$town_hs_adm<-sub(' TIMIS$',"",data[['TIMIS']]$town_hs_adm)
  data[['TIMIS']]$town_hs_adm<-if_else(grepl("TIMISOARA",data[['TIMIS']]$liceu_repartizat),"TIMISOARA",data[['TIMIS']]$town_hs_adm)
  data[['TIMIS']]$town_hs_adm<-if_else(grepl("JEBELEAN",data[['TIMIS']]$liceu_repartizat),"SANNICOLAU MARE",data[['TIMIS']]$town_hs_adm)
  data[['TIMIS']]$town_hs_adm<-if_else(grepl("SHAKESPEARE",data[['TIMIS']]$liceu_repartizat),"TIMISOARA",data[['TIMIS']]$town_hs_adm)
  data[['TIMIS']]$town_hs_adm<-if_else(grepl("BILED",data[['TIMIS']]$liceu_repartizat),"BILED",data[['TIMIS']]$town_hs_adm)
  
  data[['VALCEA']]$town_hs_adm<-if_else( data[['VALCEA']]$town_hs_adm=="","RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( is.na(data[['VALCEA']]$town_hs_adm),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("BUZESCU",data[['VALCEA']]$liceu_repartizat),"BERBESTI",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("IUSTINIAN",data[['VALCEA']]$liceu_repartizat),"BAILE OLANESTI",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("OLANESTI",data[['VALCEA']]$liceu_repartizat),"BAILE OLANESTI",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("SF NICOLAE",data[['VALCEA']]$liceu_repartizat),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("SFANTU NICOLAE",data[['VALCEA']]$liceu_repartizat),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("MATEI BASARAB",data[['VALCEA']]$liceu_repartizat),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("GHEORGHE SURDU",data[['VALCEA']]$liceu_repartizat),"BREZOI",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("BRATIANU",data[['VALCEA']]$liceu_repartizat),"DRAGASANI",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("TARNEA",data[['VALCEA']]$liceu_repartizat),"BABENI",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("BABENI",data[['VALCEA']]$liceu_repartizat),"BABENI",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("OLTCHIM",data[['VALCEA']]$liceu_repartizat),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("FERDINAND",data[['VALCEA']]$liceu_repartizat),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else( grepl("RM",data[['VALCEA']]$liceu_repartizat),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  data[['VALCEA']]$town_hs_adm<-if_else(grepl("VICTOR GIUREANU",data[['VALCEA']]$liceu_repartizat),"RAMNICU VALCEA",data[['VALCEA']]$town_hs_adm)
  
  
  data[['VRANCEA']]$town_hs_adm<-if_else(data[['VRANCEA']]$judet=='VRANCEA' & grepl("ASACHI",data[['VRANCEA']]$liceu_repartizat),"FOCSANI",data[['VRANCEA']]$town_hs_adm)
  
  data<-do.call("rbind",data)
  
  #ADJUSTMENTS BY TOWN NAME
  data$town_hs_adm<-if_else(grepl("CLUJ-NAPOCA",data$liceu_repartizat),"CLUJ-NAPOCA",data$town_hs_adm)
  data$town_hs_adm<-if_else(grepl("RAMNICU VALCEA",data$liceu_repartizat),"RAMNICU VALCEA",data$town_hs_adm)
  data$town_hs_adm<-if_else(grepl("PITESTI",data$liceu_repartizat),"PITESTI",data$town_hs_adm)
  data$town_hs_adm<-if_else((grepl("ORADEA",data$town_hs_adm)),"ORADEA",data$town_hs_adm)
  data$town_hs_adm<-if_else((grepl("BIRLAD",data$town_hs_adm)),"BIRLAD",data$town_hs_adm)
  data$town_hs_adm<-if_else((grepl("T. VLADIMIRESCU",data$town_hs_adm)),"TUDOR VLADIMIRESCU",data$town_hs_adm)
  data$town_hs_adm<-if_else(grepl("OCNA-MURES",data$town_hs_adm),"OCNA MURES",data$town_hs_adm)
  data$town_hs_adm<-if_else(grepl("SINNICOLAU",data$town_hs_adm)|grepl("SANNICOLAU",data$town_hs_adm),"SANNICOLAU-MARE",data$town_hs_adm)
  data$town_hs_adm<-if_else(grepl("SINMARTIN",data$town_hs_adm),"SANMARTIN",data$town_hs_adm)
  data$town_hs_adm<-if_else(grepl("HALINGA",data$town_hs_adm),"HALANGA",data$town_hs_adm)
  data$town_hs_adm<-if_else(grepl("PIATRA NEAMT",data$town_hs_adm),'PIATRA-NEAMT',data$town_hs_adm)
  
  
  data$town_hs_adm<-if_else(grepl("BAIAMARE",data$town_hs_adm),"BAIA MARE",data$town_hs_adm)
  
  data$town_hs_adm<-if_else(data$town_hs_adm=='TG MURES','TARGU MURES',data$town_hs_adm)
  data$town_hs_adm<-if_else(data$town_hs_adm=='NEGRESTI OAS','NEGRESTI-OAS',data$town_hs_adm)
  data$town_hs_adm<-if_else(data$town_hs_adm=='TG-JIU','TARGU-JIU',data$town_hs_adm)
  data$town_hs_adm<-if_else(data$town_hs_adm=='TG JIU','TARGU-JIU',data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='BUCUREȘTI','BUCURESTI',data$town_hs_adm)
  data$town_hs_adm<-if_else(data$judet=='BUCURESTI','BUCURESTI',data$town_hs_adm)
  data$town_hs_adm<-gsub('CIMPULUNG','CAMPULUNG',data$town_hs_adm)
  data$town_hs_adm<-gsub('CHISINEU CRIS','CHISINEU-CRIS',data$town_hs_adm)
  data$town_hs_adm<-gsub('TG\\. FRUMOS','TARGU FRUMOS',data$town_hs_adm)
  data$town_hs_adm<-gsub('RIMNICU','RAMNICU',data$town_hs_adm)
  data$town_hs_adm<-gsub('RM\\.','RAMNICU',data$town_hs_adm)
  data$town_hs_adm<-gsub("TIRGU","TARGU",data$town_hs_adm)
  data$town_hs_adm<-gsub("SFINTU","SFANTU",data$town_hs_adm)
  data$town_hs_adm<-gsub("TIRG","TARG",data$town_hs_adm)
  data$town_hs_adm<-gsub("SFANTUL GHEORGHE","SFANTU GHEORGHE",data$town_hs_adm)
  data$town_hs_adm<-if_else(data$town_hs_adm=='CLUJ','CLUJ-NAPOCA',data$town_hs_adm)
  
  data$town_hs_adm<-if_else(data$town_hs_adm=='CURTEA DE AG','CURTEA DE ARGES',data$town_hs_adm)
  
  
  #SUB TG. AND SF
  data$town_hs_adm<-sub("TG\\.","TARGU",data$town_hs_adm)
  data$town_hs_adm<-sub("SF\\.","SFANTU",data$town_hs_adm)
  
  #FINAL ADJUSTMENTS
  data$town_hs_adm<-sub("PARTICULAR","",data$town_hs_adm)
  data$town_hs_adm<-trimws(data$town_hs_adm)
  
  data_full<-data_full %>% select(-town_hs_adm)
  data_full<-base::merge(data_full,data,by=c("judet","an_adm","liceu_repartizat","liceu_repartizat_orig"))
  
  data_full<-data_full %>% 
    mutate(town_hs_adm=if_else(liceu_repartizat=='NO HS MATCHED' & liceu_repartizat=='','NOT ADMITTED',town_hs_adm)) %>%
    mutate(town_hs_adm=if_else(liceu_repartizat=='NO HS MATCHED' & liceu_repartizat!='','NO HS MATCHED',town_hs_adm)) 
  
  
  
  
  
  #TESTS:
  #1. COUNTIES, TOWNS AND NUMBER OF STUDENTS
  #test<-data_bac_raw %>% group_by(judet,town_hs_adm) %>% summarize(n=n()) %>% arrange(judet,n)
  #2. DEBUG: ALL DATA WITH TOWNS THAT CONTAIN SPECIFIC PATTERN
  #test2<-data_bac_raw[grepl("MESERII",data_bac_raw$town_hs_adm),]
  #2.1 DEBUG: ALL DATA WITH TOWNS THAT CONTAIN SPECIFIC PATTERN IN CERTAIN COUNTY
  #test2<-data_bac_raw[grepl("COOPERATIE",data_bac_raw$liceu_repartizat) & data_bac_raw$judet=="BOTOSANI",]
  #3. DATA WITHOUT TOWN
  #test2<-data_bac_raw[is.na(data_bac_raw$town_hs_adm) & !is.na(data_bac_raw$nume),] %>% group_by(liceu_repartizat) %>%
  #  summarize(n=n())
  
  return(data_full)
}